using System;
using System.Diagnostics.Contracts;

namespace Beaker.Injection
{
	/// <summary>
	/// Factory for injecting the instance of a TService delayed by providing a Factory to create it at required time.
	/// </summary>
	/// <typeparam name="TService">The type of the service to create.</typeparam>
	[ContractClass(typeof(FactoryContracts<>))]
	public interface IFactory<out TService>
		where TService : class
	{
		/// <summary>
		/// Create instance of the type TService
		/// </summary>
		/// <returns>Te created instance</returns>
		TService Create();
	}

	/// <summary>
	/// Code Contracts for the <see cref="IFactory{TService}"/> interface.
	/// </summary>
	[ContractClassFor(typeof(IFactory<>))]
	abstract class FactoryContracts<TService>
		: IFactory<TService>
		where TService : class
	{
		public TService Create()
		{
			Contract.Ensures(Contract.Result<TService>() != null);
			throw new NotImplementedException();
		}
	}

}